package com.scau.classOnline.controller;

import com.scau.classOnline.entity.Signature;
import com.scau.classOnline.model.RespEntity;
import com.scau.classOnline.service.PushLiveService;
import com.scau.classOnline.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LAN
 * @description 直播控制器
 * @date 2019/7/12
 */
@RestController
@RequestMapping("/api/live")
public class LiveController {
    @Autowired
    private PushLiveService pushLiveService;
    @Autowired
    private UserService userService;

    @GetMapping("/push")
    private RespEntity getPushCode(@RequestParam("cid") String cid) {
        return RespEntity.ok("获取推流码成功！", pushLiveService.getPushCode(cid));
    }

    @GetMapping("/sig")
    private RespEntity getUserSig(@RequestParam("uid") Integer uid) {
        Signature us = userService.getSig(uid);
        if (us != null) {
            String head = us.getSigHead();
            String tail = us.getSigTail();
            return RespEntity.ok("获取签名成功！", head + tail);
        } else {
            return RespEntity.error("获取签名失败！");
        }
    }
}
